package com.bw.module_store.view

import android.graphics.Color
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.module_store.R
import com.bw.module_store.adapter.ProgressAdapter
import com.bw.module_store.databinding.ActivityStoreMerchantDetailBinding
import com.bw.module_store.viewmodel.StoreViewModel
/**
 * 智慧园区-01-商家推荐-v1.1-吴熙-20250512
 */
@Route(path = RouterPath.PATH_STORE_MERCHANT_DETAIL_ACTIVITY)
class StoreMerchantDetailActivity :  BaseMvvmActivity<ActivityStoreMerchantDetailBinding>() {

    @JvmField
    @Autowired
    var merchantId=0

    private val viewModel : StoreViewModel by viewModels()

    lateinit var progressAdapter: ProgressAdapter

    override fun initView() {
        ARouter.getInstance().inject(this)
        viewModel.getMerchantDetail(merchantId)
        progressAdapter= ProgressAdapter()
        mDataBinding.rv.layoutManager=LinearLayoutManager(this)
        mDataBinding.rv.adapter=progressAdapter

        //头布局
        mDataBinding.topbarMerchantDetail.setBackgroundColor(Color.WHITE)
        mDataBinding.title.text="入驻申请详情"
        mDataBinding.title.setTextColor(Color.BLACK)
        mDataBinding.goBack.visibility=View.GONE
        mDataBinding.goBackBlack.visibility=View.VISIBLE
        mDataBinding.goAdd.visibility=View.GONE
        mDataBinding.goBackBlack.setOnClickListener { finish() }
    }

    override fun observeDataChange(){
        viewModel.getMerchantDetailSuccess.observe(this){
            mDataBinding.tvCode.text=it.applicationNumber
            mDataBinding.tvTime.text=it.processingSteps[0].stepTime
            mDataBinding.tvCompanyName.text=it.enterpriseName
            mDataBinding.tvConnectPerson.text=it.contactName
            mDataBinding.tvConnectMethod.text=it.contactMethod
            mDataBinding.tvEntryTime.text=it.applicationNumber
            mDataBinding.tvArea.text=it.applicationArea.toString()
            mDataBinding.tvEntryPersonCount.text="${it.entryPersonnel}人"
            mDataBinding.tvStatus.text=
                if (it.status.equals("新建")) "待确认"
                else if (it.status.equals("待审核")) "待审核"
                else if (it.status.equals("已审核")) "已审核"
                else "驳回"

            mDataBinding.tvStatus2.setBackgroundResource(
                if (it.processingSteps[it.processingSteps.size-1].business.equals("新建")) R.drawable.bg_light_blue //新建
                else if (it.processingSteps[it.processingSteps.size-1].business.equals("审核通过")) R.drawable.bg_light_green //审核通过
                else R.drawable.bg_light_red )//审核驳回

            mDataBinding.tvStatus2.setTextColor(
                if (it.processingSteps[it.processingSteps.size-1].business.equals("新建")) Color.parseColor("#1890FF") //新建
                else if (it.processingSteps[it.processingSteps.size-1].business.equals("审核通过")) Color.parseColor("#23B495") //审核通过
                else Color.RED )//审核驳回

            progressAdapter.data.clear()
            progressAdapter.data.addAll(it.processingSteps)
            progressAdapter.notifyDataSetChanged()

            if (it.processingSteps.size==1){
                mDataBinding.card2.visibility=View.GONE
                mDataBinding.card3.visibility=View.GONE
            }else if (it.processingSteps.size==2){
                mDataBinding.card3.visibility=View.GONE
            }
        }
    }

    override fun getLayoutId(): Int =R.layout.activity_store_merchant_detail
}